// 该文件专门用来创建整个项目的路由器
import VueRouter from "vue-router";
import About from "@/pages/About";
import Home from "@/pages/Home";
import News from "@/pages/News";
import Message from "@/pages/Message";
import Detail from "@/pages/Detail";

// 创建并暴露一个路由器
export default new VueRouter({
    routes: [
        // 一级路由
        {
            // 路径
            path: '/about',
            // 对应的组件
            component: About
        },
        {
            path: '/home',
            component: Home,
            // 配置二级路由
            children: [
                {
                    name: "myNews",
                    // 二级路由不需要加斜杠
                    path: 'news',
                    component: News
                },
                {
                    // 二级路由不需要加斜杠
                    path: 'message',
                    component: Message,
                    children: [
                        {
                            name: "myDetail",
                            // 占位符
                            path: 'detail/:id/:title',
                            component: Detail,
                            // props第一种写法，值为对象，该对象中的所有key-value都会传递给Detail组件
                            // props: {
                            //     a: 1,
                            //     hello: 2
                            // }
                            // props: true,
                            props: function ($route) {
                                return {
                                    id: $route.params.id,
                                    title: $route.params.title
                                }
                            }
                        }
                    ]
                }
            ]
        }
    ]
});